$(function() {
	var id = getUrlParam("id");
	//评论之星详情
	if(id) {
		getVolunteerStarByid(id);
	}

	$(".commentbox").show();

	$(".sendbtn").click(function() {
		var content=$.trim($("#commentContent").val());
		if(!content){
			alert("请输入内容");
			return;
		}
		var params = {
			"userId": cookie.get("userId"),
			"articalId":id,
			"userName":cookie.get("userName"),
			"content":content
			
		}
		$.ajax({
			type: "POST",
			url: host + "volunteerStar/addStarCommon",
			contentType: "application/json; charset=utf-8",
			data: JSON.stringify(params),
			dataType: "json",
			success: function(message) {
				alert("发表评论成功");
				$("#commentContent").val("");
			},
			error: function(message) {
				alert("发表评论失败")
			}
		});
	});
})

function getVolunteerStarByid(id) {
	$.get(host + "volunteerStar/getVolunteerStarByid/" + id, null, function(data) {
		console.log(data);
		if(data) {
			$("#title").html(data.title);
			$("#time").html(data.createDate);
			$("#source").html(data.areaName);
			$("#img").attr("src", data.imageUrl);
			$("#description").html(data.description);
			$("#starcentent").html(data.content);
			$("#commentNum").html(data.commons.length);
			$("#peopeleNum").html(data.commonNum);
			var html="";
			if(data.commons.length>0){
				$.each(data.commons, function(i,n) {
					html+='<div class="box">';
					html+='<div class="head"></div>';
					html+='<div class="nikename">'+n.userName+'</div>';
					html+='<div class="time">'+formatMsgTime(n.createDate)+'</div>';
					html+='<div class="text">'+n.content+'</div>';
					html+='</div>';
				});
			}
			$(".comment").html(html);
		}

	})
}